package net.xdclass.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.request.UserRegisterRequest;
import net.xdclass.service.FileService;
import net.xdclass.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2021-01-26
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/api/user/v1")
public class UserController {


    @Autowired
    private FileService fileService;

    /**
     * 上传文件超过1M要报错
     * @param file
     * @return
     */
    @ApiOperation("头像")
    @PostMapping(value = "upload")
    public JsonData uploadUserImg(
            @ApiParam(value = "文件上传",required = true)
            @RequestPart("file") MultipartFile file){


        String s = fileService.uploadUserImg(file);
        if (s!=null){

            return  JsonData.buildSuccess(s);
        }
        return  JsonData.buildError("上传失败");
    }



    @ApiOperation("注册")
    @PostMapping("register")
    public  JsonData register(@ApiParam("用户注册对象")@RequestBody UserRegisterRequest userRegisterRequest){




        return null;


    }



}

